package org.flexlancer.databases
{
	public class AppVars
	{
		private static const TABLE:String = "appvars";
		
		public static function Add(name:String,value:String):void{
			try{
				var insertObj:Object = new Object();
				insertObj.name = name;
				insertObj.value = value;
				DatabaseManager.Manager.Insert(TABLE,insertObj);
			}catch(err:Error){
				throw err;
			}
		}

		public static function Update(name:String,value:String):void{
			try{
				var updateObj:Object = new Object();
				updateObj.value = value;
				DatabaseManager.Manager.Update(TABLE,updateObj,"name LIKE '"+name+"'");
			}catch(err:Error){
				throw err;
			}
		}

		public static function List(condition:String = ""):Array{
			try{
				return DatabaseManager.Manager.Select(TABLE,null,condition,"name");
			}catch(err:Error){
				throw err;
			}
			return new Array;
		}
		
		public static function Delete(condition:String = ""):void{
			try{
				DatabaseManager.Manager.Delete(TABLE,condition);
			}catch(err:Error){
				throw err;
			}
		}
		public static function GetNextKitchenQT():Number{
			try{
				var arr:Array = List("name LIKE 'KITCHENQT'");
				if ( arr.length == 0 ){
					Add("KITCHENQT","1");
					return 1;
				}else{
					var num:Number = Number(arr[0].value) + 1;
					Update("KITCHENQT",num.toString());
					return num;
				}
			}catch(err:Error){
				throw err;
			}
			return -1;
		}
	}
}